package app.authorization.dto;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

@Data
@Slf4j
public class DJUserInfo implements UserDetails {

    private List<? extends GrantedAuthority> authorities;

    private Object userData;

    private Object response;

    private String phone;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getPassword() {
        return null;
    }

    @Override
    //获取存储到redis中的
    public String getUsername() {
        Object data = this.getUserData();
        if (data instanceof MemberInfo) {
            MemberInfo userData = (MemberInfo) this.getUserData();
            Integer id = userData.getId();
            String idStr = String.valueOf(id);
            return idStr + "_" + userData.getLoginDeviceStr();

        }
        log.error("登录错误！----- 获取存储redis的key错误");
        if (data == null) {
            return "";
        }
        return data.toString();
    }

    @Override
    public boolean isAccountNonExpired() {
        return false;
    }

    @Override
    public boolean isAccountNonLocked() {
        return false;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return false;
    }

    @Override
    public boolean isEnabled() {
        return false;
    }
}
